﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HelpCentral.Shared.Validation;

namespace HelpCentral.Shared.Interfaces
{
    public static class ValidationExtensions
    {
        public static void Validate(this IClient source)
        {
            if (string.IsNullOrEmpty(source.Name) || source.Name.Length > 100)
            {
                throw new ValidationException("Name must be 100 characters or less, and not null or empty.");
            }
            else if (source.License == null || source.License == Guid.Empty)
            {
                throw new ValidationException("License is not valid.");
            }
            else if (source.DeactivateDate != null && source.ActivateDate > source.DeactivateDate)
            {
                throw new ValidationException("Invalid activation date.");
            }
        }

        public static void Validate(this IAuditEvent source)
        {
            if (source.EventType.ToString().Length > 255 || source.EventType == Enums.AuditEventType.UnknownEvent)
            {
                throw new ValidationException("Invalid event type.");
            }
        }

        public static void Validate(this IUser source)
        {
            if (string.IsNullOrEmpty(source.Username) || source.Username.Length > 40)
            {
                throw new ValidationException("Invalid username. Cannot be null, empty, or more than 40 characters.");
            }
            else if (source.PasswordHash == null)
            {
                throw new ValidationException("Password hash cannot be null.");
            }
            else if (source.ADUsername != null && source.ADUsername.Length > 255)
            {
                throw new ValidationException("ADUsername cannot be more than 255 characters.");
            }
            else if (source.DeactivateDate != null && source.ActivateDate > source.DeactivateDate)
            {
                throw new ValidationException("Invalid activation date.");
            }
        }
    }
}
